package com.example.hzq.zqb.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.hzq.zqb.R;
import com.squareup.picasso.Picasso;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.example.hzq.zqb.fragment.Fragment1.imageurl;

/**
 * Created by hzq on 2017/7/13.
 */

public class GridAdapter extends BaseAdapter {
    private List<HashMap<String, Object>> data;
    private LayoutInflater layoutInflater;
    private Context context;
    public   GridAdapter(Context context,List<HashMap<String, Object>> data){
        this.context=context;
        this.layoutInflater=LayoutInflater.from(context);
        this.data=data;

    }
    @Override
    public int getCount() {
        return data.size();
    }
    public final class Zujian{
        public ImageView image;
        public TextView title;
    }
    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Zujian zujian=null;
        if(convertView==null){
            zujian=new Zujian();
            //获得组件，实例化组件
            convertView=layoutInflater.inflate(R.layout.griditem, null);
            zujian.image=(ImageView)convertView.findViewById(R.id.gridimage);
            zujian.title=(TextView)convertView.findViewById(R.id.gridtext);
            convertView.setTag(zujian);
        }else{
            zujian=(Zujian)convertView.getTag();
        }
        Picasso.with(context).load(String.valueOf(data.get(position).get("ItemImage"))).placeholder(R.drawable.ic_default_adimage).into(zujian.image);
        zujian.title.setText(String.valueOf(data.get(position).get("ItemText")));
        return convertView;
    }
}
